using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace WenXia
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class BackgroundManager : Microsoft.Xna.Framework.DrawableGameComponent
    {
        private Texture2D t2dTemple;
        private Texture2D t2dTriangle;
        private SpriteBatch spriteBatch;
        private List<Texture2D> texs;
        private int backgroundIndex;
        private Color backgroundColor = Color.White;

        public Color BackgroundColor
        {
            get { return backgroundColor; }
            set { backgroundColor = value; }
        }
        public int BackgroundIndex
        {
            get { return backgroundIndex; }
            set { backgroundIndex = value; }
        }
        public BackgroundManager(Game game)
            : base(game)
        {
            this.DrawOrder = 0;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);
            base.Initialize();
        }
        protected override void LoadContent()
        {
            t2dTemple = Game.Content.Load<Texture2D>(@"temple");
            t2dTriangle = Game.Content.Load<Texture2D>(@"triangle");
            texs = new List<Texture2D>();
            texs.Add(t2dTemple);
            texs.Add(t2dTriangle);
            base.LoadContent();
        }
        protected override void UnloadContent()
        {
            foreach (Texture2D t in texs)
            {
                t.Dispose();
            }
            texs.Clear();
            base.UnloadContent();
        }
        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred,BlendState.AlphaBlend,SamplerState.AnisotropicClamp,null,null);
            spriteBatch.Draw(texs[backgroundIndex],new Rectangle(0,0,Game.Window.ClientBounds.Width,Game.Window.ClientBounds.Height),backgroundColor);
            spriteBatch.End();
            base.Draw(gameTime);
        }
        
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {

            base.Update(gameTime);
        }
    }
}
